<?php
namespace app\serverfund\service\currency;

use \app\manage\service\ApiBase;
/**
 * @author:      李颖
 * @DateTime:    2017-06-29 15:13:24
 * @Description: 数字币拆分
 */
class CurrencySplitLog extends ApiBase
{
    protected $currencySplitLogValidate = '\app\serverfund\validate\CurrencySplitLog';
    protected $currencySplitLogLogic = '\app\serverfund\logic\CurrencySplitLog';

    //封装一层检验user_info、opposite_info后再执行stepRun <该页多数方法都需检验这两个json数据>
    protected function _checkJsonThenRun(array $data, string $method, string $scene = ''): array 
    {
        if(isset($data['user_info']) && $data['user_info'] !== '{}'){ $data['user_info'] = json_encode($data['user_info']); }
        if(isset($data['opposite_info']) && $data['opposite_info'] !== '{}'){ $data['opposite_info'] = json_encode($data['opposite_info']); }

        return $this->stepRun($data, $method, $scene);
    }

    /*数字币拆分*/
    public function split(): array 
    {
    	$data = $this->haveIssetReceiveData(['user_id'=>'0', 'currency'=>'0', 'lock_key'=>'', 'get_key'=>'', 'update_ip'=>' ', 'app_id'=>' ', 'user_info'=>'{}','opposite_info'=>'{}']);
    	return $this->_checkJsonThenRun($data, 'split', 'split');
    }

    /*交易方锁定亚数币*/
    public function lock(): array 
    {
    	$data = $this->haveIssetReceiveData(['user_id'=>'0', 'public_key'=>' ', 'lock_key'=>' ', 'update_ip'=>' ', 'app_id'=>' ', 'user_info'=>'{}','opposite_info'=>'{}']);
    	return $this->_checkJsonThenRun($data, 'lock', 'lock');
    }

    /*交易方读取锁定的亚数币*/
    public function readLock(): array 
    {
    	$data = $this->haveIssetReceiveData(['user_id'=>'0', 'public_key'=>' ', 'get_key'=>' ', 'update_ip'=>' ', 'app_id'=>' ', 'user_info'=>'{}','opposite_info'=>'{}']);
    	$data['is_lock'] = 1;
    	return $this->_checkJsonThenRun($data, 'read', 'readLock');
    }

    /*交易方直接读取亚数币*/
    public function read(): array 
    {
    	$data = $this->haveIssetReceiveData(['user_id'=>'0', 'public_key'=>' ', 'get_key'=>' ', 'update_ip'=>' ', 'app_id'=>' ', 'user_info'=>'{}','opposite_info'=>'{}']);
    	$data['is_lock'] = 0;
    	return $this->_checkJsonThenRun($data, 'read', 'read');
    }

    /*冻结亚数币*/
    public function freeze(): array
    {
        $data = $this->haveIssetReceiveData(['user_id'=>'0', 'opposite_id'=>'0', 'currency'=>'0', 'update_ip'=>' ', 'app_id'=>'0', 'user_info'=>'{}','opposite_info'=>'{}']);
        return $this->_checkJsonThenRun($data, 'freeze', 'freeze');
    }

    /*解冻亚数币*/
    public function unfreeze(): array
    {
        $data = $this->haveIssetReceiveData(['user_id'=>'0', 'opposite_id'=>'0', 'currency'=>'0', 'update_ip'=>' ', 'app_id'=>'0', 'freeze_log_id'=>'0', 'user_info'=>'{}','opposite_info'=>'{}']);
        return $this->_checkJsonThenRun($data, 'unfreeze', 'unfreeze');
    }

    /*获取数字币拆分记录*/
    public function list(): array 
    {
        $data = $this->haveIssetReceiveData(['page'=>'1', 'list_rows'=>'']);
        return $this->stepRun($data, 'list', 'list');
    }

    //获取指定用户的数字币拆分记录
    public function listByUserIds(): array
    {
        $data = $this->haveIssetReceiveData(['page'=>'1', 'list_rows'=>'', 'user_ids'=>' ']);
        return $this->stepRun($data, 'listByUserIds', 'listByUserIds');
    }

    /*获取某个用户的某个状态下的列表*/
    public function listByUserStatus(): array
    {
        $data = $this->haveIssetReceiveData(['user_id'=>'0', 'status'=>' ', 'page'=>'1', 'list_rows'=>''], []);
        return $this->stepRun($data, 'listByUserStatus', 'listByUserStatus');
    }


}